package com.touni.datastructure;

/**
 * @ClassName : DemoQueue
 * @Description :
 * @Author : lwq
 * @Date: 2021-04-23 15:28
 */
public class DemoQueue<T> {

    private Object[] data;

    private int head = 0; //队头 出

    private int tail = 0;// 队尾 进

    private int size;

    public DemoQueue(){
        this.data = new Object[16];
        this.size = 16;
    }

    public DemoQueue(int size){
        this.data = new Object[size];
        this.size = size;
    }

    public void resize(){
        Object[] temp = new Object[size * 2];
        System.arraycopy(data,0,temp,0,size);
        size = size*2;
        data = temp;
    }

    public boolean add(T value){
        if (tail > size){
            resize();
        }
        data[tail] = value;
        tail++;
        return Boolean.TRUE;
    }

    public T poll(){
        T value = (T) data[head];
        data[head] = null;
        head++;
        return value;
    }

    public T peek(){
        return (T) data[head];

    }


}
